package view.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JRadioButton;

import model.Constants;
import view.dialogs.AddIpByListDialog;
import view.dialogs.AddSimpleIpDialog;
import view.dialogs.ChooseOptionDialog;
import view.dialogs.MultiIpAddDialog;

public class ChooseOptionListener implements ActionListener {

	private final ChooseOptionDialog chooseDialog;
	private final ArrayList<JRadioButton> buttonPanel;

	public ChooseOptionListener(ChooseOptionDialog chooseOptionDialog,
			ArrayList<JRadioButton> buttons) {
		this.chooseDialog = chooseOptionDialog;
		this.buttonPanel = buttons;
	}

	@Override
	public void actionPerformed(ActionEvent e) {

		for (JRadioButton element : buttonPanel) {
			
			if (element.isSelected()) {

				switch (buttonPanel.indexOf(element)) {

				case 0:
					chooseDialog.closeDialog();
					new AddSimpleIpDialog(Constants.ADDIPTITLE);
					break;
				case 1:
					chooseDialog.closeDialog();
					new AddIpByListDialog(Constants.ADDIPTITLE);
					break;
				case 2:
					chooseDialog.closeDialog();
					new MultiIpAddDialog(Constants.ADDIPTITLE);
					break;

				}

			}
		}
	}
}



